package org.dce.screencapturer.objects;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;

public class DrawingObjectBeanInfo extends SimpleBeanInfo {

	private final Class<? extends DrawingObject> objectClass;
	
	protected DrawingObjectBeanInfo(Class<? extends DrawingObject> objectClass){
		this.objectClass = objectClass;
	}
	
	public DrawingObjectBeanInfo(){
		this(DrawingObject.class);
	}
	
	@Override
	public PropertyDescriptor[] getPropertyDescriptors() {
		try {
			return new PropertyDescriptor[]{
					createProperty("location","Location"),
					createProperty("size","Size"),
					createProperty("bounds","Bounds"),
			};
		}catch (Exception ex){
			throw new RuntimeException(ex);
		}
	}
	
	protected PropertyDescriptor createProperty(String name,String displayName) throws IntrospectionException{
		PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass);
		descriptor.setDisplayName(displayName);
		return descriptor;
	}

	protected PropertyDescriptor[] add(PropertyDescriptor[] array, PropertyDescriptor ...descriptors){
		PropertyDescriptor[] newArray = new PropertyDescriptor[array.length+descriptors.length];
		
		System.arraycopy(array, 0, newArray, 0, array.length);
		System.arraycopy(descriptors, 0, newArray, array.length, descriptors.length);
		
		return newArray;
	}
}
